package com.itheima.stock.face.impl;

import com.itheima.stock.face.StockCacheFace;
import com.itheima.stock.mapper.StockBusinessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 缓存层实现
 */
@Component("stockCacheFace")
public class StockCacheFaceImpl implements StockCacheFace {

    @Autowired
    private StockBusinessMapper stockBusinessMapper;

    @Override
    @Cacheable(cacheNames = "stock",key = "'stockConde'")
    public List<String> getAllStockCodeWithPredix() {
        //1.获取所有个股的集合3000+
        List<String> allStockCode = stockBusinessMapper.getAllStockCode();
        //编码以6开头加sh 不是加sz
        //一次性将所有集合拼接到urL地址中，导致地址过长，参数过多
        allStockCode =  allStockCode.stream().map(code->code.startsWith("6")?"sh"+code:"sz"+code).collect(Collectors.toList());


        return allStockCode;
    }
}
